/**
 * Copyright (C) 2012-2013 jumei, Inc.
 * Test.java
 * 2015年6月23日
 */
package org.goface.rpc;

import java.util.concurrent.ExecutionException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.google.common.util.concurrent.SettableFuture;

/**
 * 
 * @author jm110
 */
public class TestRpc {
static	Logger logger = LoggerFactory.getLogger(TestRpc.class);

	public static void main1(String[] args) throws Exception {
		ClassPathXmlApplicationContext ctx;
		ctx = new ClassPathXmlApplicationContext(new String[] {
				"META-INF/base.xml", "service.xml" });
		// ConfigurableListableBeanFactory beanFactory = ctx.getBeanFactory();
		// beanFactory.addBeanPostProcessor(new RpcBeanPostProcessor());
		com.goface.people.PeopleService ca = (com.goface.people.PeopleService) ctx
				.getBean("peopleServiceClient");
		ca.create("ddd", 23);
		System.out.println(ca);

	}

	public static void main2(String[] args) {
		final SettableFuture<String> sf = SettableFuture.create();
		Thread t = new Thread(new Runnable() {

			@Override
			public void run() {
				try {
					Thread.sleep(10000);
					// sf.set("response");
					sf.setException(new RuntimeException("ex"));
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		t.start();
		try {
			String ret = sf.get();
			System.out.println(ret);
		} catch (InterruptedException | ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void f(int k) {
		System.out.println("===" + k);

	}

	public static void main(String[] args) throws Exception {
		logger.info("begin");
		RPC.init();
		com.goface.people.PeopleService ca = (com.goface.people.PeopleService) RPC
				.getBean("peopleServiceClient");
		int ret=ca.create("ddd", 23);
		System.out.println(ret);
		// Integer in=new Integer(12);
		// f(in);
		// System.out.println((int)in);
		// int t=1;
		// Class<?> cl= int.class;
		// System.out.println(cl);
	}

}
